package com.zr.controller.car

import com.alibaba.fastjson.JSON
import com.github.pagehelper.PageInfo
import com.zr.service.car.Impl.CarServerImpl
import com.zr.util.Result
import com.zr.vo.car.Car
import com.zr.vo.sys.User
import io.netty.handler.codec.base64.Base64Encoder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.repository.query.Param
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile

@RestController
@RequestMapping("/car/Car")
class CarController {

    @Autowired
    val carServer: CarServerImpl?=null

    @RequestMapping("/listCarsByCar")
    fun listCarsByCar(@RequestBody car: Car):String{
        val selectResult=carServer?.listCarsByCar(car)
        val pageInfo=PageInfo<Car>(selectResult)
        val result=Result(true,"查询成功",pageInfo)
        return JSON.toJSONString(result)
    }
    @RequestMapping("/add")
    fun add(@RequestBody car:Car):String{
        carServer?.add(car)
        return JSON.toJSONString(Result(true,"添加成功",null))
    }
    @RequestMapping("/del")
    fun del(@RequestBody car:Car):String{
        carServer?.deleteByCar(car)
        return JSON.toJSONString(Result(true,"删除成功",null))
    }
    @RequestMapping("/edit")
    fun edit(@RequestBody car:Car):String{
        carServer?.edit(car)
        return JSON.toJSONString(Result(true,"修改成功",null))
    }
    @RequestMapping("/uploadCarImg")
    fun uploadCarImg( file:MultipartFile):String{
        carServer?.uploadCarImg(file)
        return JSON.toJSONString(Result(true,"上传成功",null))
    }
    @RequestMapping("/loadImg")
    fun loadImg(@RequestBody car:Car):String?{
        val base64= carServer?.loadImg(car)
        return JSON.toJSONString(Result(true,base64,null))
    }
}